package org.noobie.photopicker.entity;

import android.os.Parcel;
import android.os.Parcelable;

public class Photo implements Parcelable {
    private final String filePath;
    private boolean isChecked;

    public Photo(String filePath) {
        this.filePath = filePath;
        this.isChecked = false;
    }

    public Photo(String filePath, boolean isChecked) {
        this.filePath = filePath;
        this.isChecked = isChecked;
    }

    private Photo(Parcel in) {
        filePath = in.readString();
        isChecked = in.readInt() == 1;
    }

    public static final Creator<Photo> CREATOR = new Creator<Photo>() {
        @Override
        public Photo createFromParcel(Parcel in) {
            return new Photo(in);
        }

        @Override
        public Photo[] newArray(int size) {
            return new Photo[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(filePath);
        dest.writeInt(isChecked ? 1 : 0);
    }

    public String getFilePath() {
        return filePath;
    }

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean isChecked) {
        this.isChecked = isChecked;
    }

    @Override
    public boolean equals(Object obj) {
        return this == obj || (obj != null && obj instanceof Photo && (filePath == null ? ((Photo) obj).filePath == null : filePath.equals(((Photo) obj).filePath)));
    }
}
